

def decorator(cls):

    class Wrapper:
        def __init__(self, *args, **kwargs):
            self.wrapped = cls(*args, **kwargs)

        def __getattr__(self, name):
            return getattr(self.wrapped, name)

        def method(self):
            return repr(self)

    return Wrapper


@decorator
class TestCls:    # 等价于test_cls = decorator(test_cls)

    def __init__(self, x, y):
        self.attr_x = x
        self.attr_y = y

    def method(self):
        return self.attr_x, self.attr_y


if __name__ == "__main__":
    c = TestCls(3, 4)
    # print(c.attr_x)
    # print(hasattr(c, "attr_x"))
    # print(c.attr_y)
    # print(c.method())
    print(getattr(c, "method")())
